<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
 * SugarCRM is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 * 
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by SugarCRM".
 ********************************************************************************/

function additionalDetailsedanz_Editor($fields) {
	global $mod_strings;
	$mod_strings = return_module_language($GLOBALS['current_language'], 'edanz_Editor');
	$overlib_string = '<strong>'.$mod_strings['UNCOMPLETED_TASKS'].'</strong><br/>';

	require_once('modules/edanz_Editor/edanz_Editor.php');
	$focus = new edanz_Editor();
	$focus->retrieve($fields['ID']);
	$tasks = $focus->get_linked_beans('tasks', 'Task');
	foreach($tasks as $task) {
		if(in_array($task->status,array('Not Started','In Progress','Pending Input','Deferred'))){
			$overlib_string .= $task->name . '<br/>';
		}
	}
	return array(
		'fieldToAddTo' => 'NAME',
                'string' => $overlib_string,
				// 'editLink' => "index.php?action=FeedbackConstruction&module=edanz_Editor&return_module=edanzFeedback&record={$fields['ID']}",
	);
}
 
function generateDate($dateObj)
{
       return $dateObj->year."-".$dateObj->zmonth."-".$dateObj->zday;
}

function scheduleDetails($editor_id, $start_time = NULL){
	global $mod_strings, $app_strings, $app_list_strings, $timedate, $db;
//        $mod_strings = return_module_language($GLOBALS['current_language'], 'edanz_Editor');
	$notes_panel = '';
	$unavailable = false;

	$query = "SELECT id, name, type, valid_from, valid_to FROM edanz_schedulenotes WHERE edanz_schedulenotes.related_editor_id= '$editor_id' AND edanz_schedulenotes.deleted=0 ORDER BY date_modified desc";
	$result = $db->query($query, true);
	while($schedule_note = $db->fetchByAssoc($result)) {
		$note = "<a href='index.php?module=edanz_ScheduleNotes&action=DetailView&record=".$schedule_note['id']."' title='' target='_blank'>".$schedule_note['name']."</a>";
		// Check that day is between from and to dates (inclusive)
		if(empty($start_time) && empty($schedule_note['valid_to'])){
                        $notes_panel .= '<table cellspacing=0 cellpadding=0 border=0 ><tr><td><strong>'.$mod_strings['LBL_TYPE'].'</strong>'.$app_list_strings['schedule_note_types'][$schedule_note['type']].'</td></tr>';
                        $notes_panel .= '<tr><td><strong>'.$mod_strings['LBL_NOTE'].'</strong>'.$note.'</td></tr></table><hr>';
/*			if($schedule_note['type'] == 'ReceiptUnavailability' || $schedule_note['type'] == 'ReturnUnavailability'){
				$unavailable = true;
			}

*/
		}elseif(!empty($schedule_note['valid_to']) && generateDate($start_time) >= $schedule_note['valid_from'] && generateDate($start_time) <= $schedule_note['valid_to']){
			$notes_panel .= '<table cellspacing=0 cellpadding=0 border=0 ><tr><td><strong>'.$mod_strings['LBL_TYPE'].'</strong>'.$app_list_strings['schedule_note_types'][$schedule_note['type']].'</td><td><strong>'.$mod_strings['LBL_DURATION'].'</strong>'.$timedate->to_display_date($schedule_note['valid_from'],false) . ' - '.$timedate->to_display_date($schedule_note['valid_to']).'</td></tr>';
			$notes_panel .= '<tr><td colspan=2><strong>'.$mod_strings['LBL_NOTE'].'</strong>'.$note.'</td></tr></table><hr>';
			if($schedule_note['type'] == 'ReceiptUnavailability' || $schedule_note['type'] == 'ReturnUnavailability'){
                                $unavailable = true;
                        }

		}
		if(empty($schedule_note['valid_to']) && generateDate($start_time) >= $schedule_note['valid_from'] && ($schedule_note['type'] == 'ReceiptUnavailability' || $schedule_note['type'] == 'ReturnUnavailability')){
				$unavailable = true;
			}
	}

	$probation_text = '';
	$query = "SELECT id, name FROM edanz_probation WHERE related_editor_id= '$editor_id' AND status = 'Active' AND deleted=0 ORDER BY date_modified desc";
        $result = $db->query($query, true);
        while($probation = $db->fetchByAssoc($result)) {
		$probation_text .= "<a href='index.php?module=edanz_Probation&action=DetailView&record=".$probation['id']."' title='' target='_blank'>".$probation['name']."</a>";
	}
	return array(
		'schedule_notes' => $notes_panel,
		'probation_notes' => $probation_text,
		'unavailable' => $unavailable,
	);
}

 ?>
 
 
